package org.dtrd.modules.service.entity.bean;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.dtrd.common.util.StringUtil;
import org.dtrd.config.pay.OrderUtil;
import org.dtrd.modules.service.entity.po.DtrdEntRdServicePackage;
import org.hibernate.validator.constraints.Range;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 服务包信息
 * </p>
 *
 * @author QR
 * @since 2021-11-19 18:52:54
 */
@Data
@ApiModel(value = "服务包数据")
public class ServicePackageInfo {

    private Integer dataId;

    @NotNull
    @ApiModelProperty(value = "服务包名字", required = true)
    private String packageName;

    @NotNull
    @ApiModelProperty(value = "服务包服务周期", required = true)
    private Integer packageServicePeriod;

    @NotNull
    @ApiModelProperty(value = "服务包原价")
    private Float packagePrice;

    @NotNull
    @ApiModelProperty("服务包折扣价")
    private Float packageDiscount;

    @NotNull
    @Range(min = 1, max = 2)
    @ApiModelProperty(value = "服务类型", notes = "服务类型, 2-体验式服务, 1-正式服务")
    private Integer packageType;

    @ApiModelProperty(value = "服务包详情", notes = "一般是一个长海报, 目前只有体验包有")
    private String packageDetail;

    @ApiModelProperty(value = "轮播图", notes = "目前轮播图设计成4张, 2022-1-19")
    private String packageSlideshow;

    @ApiModelProperty(value = "服务包描述", notes = "目前只有体验包有")
    private String packageDesc;

    @ApiModelProperty(value = "缩略图")
    private String packageThumb;

    private Boolean packageTypeStatus;

    @ApiModelProperty(value = "机构编码")
    @NotNull
    private String orgCode;

    @ApiModelProperty(value = "管理成效")
    @NotEmpty
    @Valid
    private List<ManageEffect> manageEffect;


    public ServicePackageInfo parseFromPo(DtrdEntRdServicePackage po) {
        dataId = po.getDataId();
        packageName = po.getPackageName();
        packageServicePeriod = po.getPackageServicePeriod();
        packagePrice = wrappPrice(po.getPackagePrice());
        packageDiscount = wrappPrice(po.getPackageDiscount());
        packageDetail = po.getPackageDetail();
        packageSlideshow = po.getPackageSlideshow();
        packageDesc = po.getPackageDesc();
        packageType = po.getPackageType();
        packageThumb=po.getPackageThumb();
        if (StrUtil.isNotBlank(po.getManageEffect())) {
            manageEffect = JSON.parseArray(po.getManageEffect(), ManageEffect.class);
        }
        return this;
    }

    private Float wrappPrice(Integer price) {
        if (price != null) {
            return StringUtil.StrTrimFloat(OrderUtil.changeF2Y(Long.valueOf(price)));
        }
        return null;
    }

}
